<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/adminHead.jsp" %>
<LINK href="${cssUrl}/admin.css" rel="stylesheet" type="text/css">
  <TR>
    <TD height="%" valign="top">
      <TABLE width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
        <TBODY>
        <TR>
          <TD width="186" height="%" align="right" valign="top"><!-- Left Menu table 시작 --------------------------------> 
                        
            <TABLE width="176" height="100%" border="0" cellspacing="0" 
            cellpadding="0">
              <TBODY>
              <TR>
                <TD height="53"><IMG src="${imgUrl}/left_top_title.gif"></TD></TR>
              <TR>
                <TD height="%" background="${imgUrl}/left_bg.gif" valign="top" 
                style="padding: 5px 0px 0px 5px;"><!-- Menu table 끝 * css사용 해당메뉴의 페이지일때는  class="leftmenu_b", 해당 메뉴페이지가 아닐경우  class="leftmenu"로 사용--------------------------------> 
                  <TABLE width="150" style="margin-top: 10px;" border="0" 
                  cellspacing="0" cellpadding="0">
                    <TBODY>
                    <c:forEach var = "menu" items="${menuList}">					
						<tr>
							<td height="25"><img src="${imgUrl}/left_icon.gif" border="0" align="absmiddle"/>
								<a class="leftmenu" href="javascript:goAdminBoardListMain(<c:out value="${menu.menuIndex}" />, <c:out value="${menu.menuType}" />)"><c:out value="${menu.menuName}" /></a>
							</td>
						</tr>				
					</c:forEach>
					<tr>
						<td height="25"><img src="${imgUrl}/left_icon.gif" border="0" align="absmiddle"/><a class="leftmenu" href="javascript:goAdminMenuList();">&nbsp;메뉴관리</a></td>
					</tr>
						</TBODY></TABLE></TD></TR></TBODY></TABLE><!-- Left Menu table 끝 --------------------------------> 
                    </TD>
          <TD width="%" align="right" valign="top" style="padding: 20px 10px 0px 0px;">
            <TABLE width="97%" border="0" cellspacing="0" cellpadding="0">
              <TBODY>
              <TR>
                <TD align="left" class="admin_title" background="${imgUrl}/title_bg.gif" 
                valign="middle"><IMG align="absmiddle" src="${imgUrl}/title_icon.gif"><c:out value="${menuName}" /></TD></TR>
              <TR>
                <TD height="20">&nbsp;</TD></TR>
              <TR>
                <TD>
                  <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
                    <TBODY>
                    <TR>
                      <TD>
                       <TABLE width="100%" bgcolor="#d9d9d9" border="0" cellspacing="1" cellpadding="0">
                          <TR>
                            <TD height="1" bgcolor="#3f8bc9" colspan="7"></TD>
                          </TR>
                          <TR>
                            <TD width="11%" align="center" class="top_blue3" 
                            bgcolor="#eff3fa">번호</TD>
                            <TD width="*" align="center" class="top_blue3" 
                            bgcolor="#eff3fa">제목</TD>
                            <TD width="9%" align="center" class="top_blue3" 
                            bgcolor="#eff3fa">구매포인트</TD>
                            <TD width="9%" align="center" class="top_blue3" 
                            bgcolor="#eff3fa">누적포인트</TD>
                            <TD width="9%" align="center" class="top_blue3" 
                            bgcolor="#eff3fa">작성일</TD>
                            <TD width="9%" align="center" class="top_blue3" 
                            bgcolor="#eff3fa">조회수</TD>
                           </TR>
                          </TABLE>
                          <TABLE width="100%" bgcolor="#d9d9d9" border="0" cellspacing="1" cellpadding="0" id="boardList">
						   <TR onClick="adminBoardView(this)" style="cursor:hand;">
                            <TD width="11%" align="center" class="list_dark" bgcolor="#ffffff" id="textNum"></TD>
                            <TD width="*%" class="list_dark_l" bgcolor="#ffffff" id="title"></TD>
                            <TD width="9%" align="center" class="list_dark" bgcolor="#ffffff" id="usePoint"></TD>
                            <TD width="9%" align="center" class="list_dark" bgcolor="#ffffff" id="sumPoint"></TD>
                            <TD width="9%" align="center" class="list_dark" bgcolor="#ffffff" id="regiTime"></TD>
							<TD width="9%" align="center" class="list_dark" bgcolor="#ffffff" id="viewCnt"></TD>
							<TD style="display:none"><input type="hidden" id="textID"></TD>
						  </tr>
                                                   
                       </TABLE><!--리스트 테이블 끝--></TD></TR>
                    <TR>
                      <TD height="30" align="right" valign="bottom" 
                        colspan="7"><IMG src="${imgUrl}/btn_write.gif" onclick="adminBoardWrite()" style="cursor:hand"></TD></TR>
                    <TR>
                      <TD height="35" align="center" valign="middle" colspan="7">
                      	<div id="pagenation"></div>
                      </TD></TR>
                    <TR>
                      <TD align="center" colspan="7">
                        <TABLE border="0" cellspacing="0" cellpadding="0">
                          <FORM name="fsearch" style="margin: 0px;" method="post" onkeydown="hitEnterKey(event)" onsubmit="return false;">
						
                              <TBODY>
                          <TR>
                            <TD align="middle" valign="middle" style="padding: 3px 0px 0px 5px;">
                            <SELECT name="searchType" class="inputText" id="searchType">
                            	<OPTION value="1" selected>본문</OPTION>                        
                                <OPTION value="2" >제목</OPTION>             
                            </SELECT>                         
							<INPUT name="searchName" class="inputText" type="text" size="30" maxlength="25" id="searchName">
							</TD>
                            <TD align="right" valign="middle" style="padding-left: 5px;">
                            	<img style="cursor: hand;" src="${imgUrl}/n_search.gif" hspace="3" onClick="getSearchBoardList()">
                            </TD></TR></TBODY></TABLE></TD></TR>  </FORM>
                    <TR>
                      <TD>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<form style="display:none;" id="frm" name="frm" method="post">
	<input type="hidden" name="menuIndex" id="menuIndex" value="${menuIndex}">
	<input type="hidden" name="textID" id="paramTextID">
	<input type="hidden" name="mode" id="mode">
</form>
<script type="text/javascript">
  var _this = this;
  var markerSetting = {
  		paging:{}
  }
  init();
  function init() {
  		markerSetting.paging.page = '<c:out value="${totalPage.page}"/>';
		markerSetting.paging.totalPage ='<c:out value="${totalPage.totalPage}"/>';
		markerSetting.paging.nowSeq = 1;
		markerSetting.paging.menuIndex = $("#menuIndex").val();
		getBoardList();
  }
  
  function getBoardList() {
  	_this.boardList = tableSync('boardList');
  	var url='getAdminBoardList.json';
  	markerSetting.paging.searchType = $("select[name=searchType]").val();
  	markerSetting.paging.searchName = $("#searchName").val();
		var param=markerSetting.paging;
		
		AjaxPost(url, param, function(data){
//	 		jsonLog(data.boardList);
			$.each(data.boardList,function(index, value){
				value.regiTime = formatter.dateFormatYYYYMMDDHHMMSS2(new Date(value.regiTime));
			});
			_this.boardList.tableAutoSync(data.boardList);
			markerSetting.paging.totalPage= data.totalPage.totalPage;
			makePaging();
		});
  }
  
  function getSearchBoardList() {
	  markerSetting.paging.searchType = $("select[name=searchType]").val();
	  markerSetting.paging.searchName = $("#searchName").val();
	  
	  getBoardList();
  }
  function makePaging() {
  	$('#pagenation').html("");
		var totalPage = markerSetting.paging.totalPage;
		var nowPage = markerSetting.paging.page;
		var html='';
		var setFunctionName='';
		var index=(nowPage-10);
		var indexCount=0;
		
		var endPage = totalPage / 10;
		if (totalPage % 10 > 0) {
			endPage = endPage + 1;
		}
		if(index > 1){
			html+='<a onclick="changePaging(1,\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_first.jpg"/ alt=처음 align=absmiddle style="/cursor:hand;/"></a>';
			html+='<a onclick="changePaging('+index+',\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_prev.jpg"/  alt=이전 align=absmiddle style="/cursor:hand;/"></a>&nbsp;&nbsp;';
		}
//		//logs('totalPage/20 = '+totalPage/20);
		for(;index<=endPage;index++){
			if((index)==nowPage){
				setFunctionName='';
			}else{
				setFunctionName=' onclick="changePaging('+index+')"';
			}
			
			if(index>0){
				if(index == nowPage) {
					html+='<a '+setFunctionName+'><b>'+index+'</b></a>&nbsp;';
				} else {
					html+='<a '+setFunctionName+' style=cursor:hand;>'+index+'</a>&nbsp;';
				}
				
				indexCount++;
			}
			if(indexCount>9){
				html+='<a onclick="changePaging('+index+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_next.jpg"/  alt=다음 align=absmiddle style="/cursor:hand;/"></a>';
				html+='<a onclick="changePaging('+totalPage+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_last.jpg"/  alt=맨끝 align=absmiddle style="/cursor:hand;/"></a>';
				break;
			}
			
		}
		$('#pagenation').html(html);
  }
  
  function changePaging(index, option){
		logs('markerSetting.paging.totalPage = '+markerSetting.paging.totalPage);
		if(option==null){
			logs(', index = '+index);
			
			markerSetting.paging.page=index;
			markerSetting.paging.start=0;
			markerSetting.paging.end=0;
			getBoardList();
		}else{
			if(option=='before'){
				var next = index-9;
				while(next<=0){
					next++;
				}
				logs('next = '+next+', index = '+index);
				markerSetting.paging.page=next;
				markerSetting.paging.start=0;
				markerSetting.paging.end=0;
				getBoardList();
			}else if(option=='after'){
				var next = index+9;
				while(next>=(markerSetting.paging.totalPage/10)+1){
					next--;
				}
				logs('next = '+next+', index = '+index);
				markerSetting.paging.page=next;
				markerSetting.paging.start=0;
				markerSetting.paging.end=0;
				getBoardList();
			}
		}
	}
  
  function adminBoardWrite() {
	$("#mode").val("insert");
  	$("#frm").attr("action", "/admin/adminBoardWrite");
	$("#frm").submit();
  }
  
  function goAdminBoardListMain(type, menuType) {
	// type = 1 공지사항
		// type = 2 최신판례
		// type = 3 최신법령
		// type = 4 A항목
		// type = 5 B항목
		// type = 6 C항목
		// type = 7 D항목
		// type = 8 E항목
		// type = 9 F항목
		// type = 10 G항목
		// type = 11 H항목
		$("#menuIndex").val(type);
		var url;
		
		if (menuType == 0) {
			url = "/admin/adminBoardMain";	
		} else {
			url = "/admin/adminBoard2Main";
		}
					
		$("#frm").attr("action", url);
		$("#frm").submit();
		
  }
  
  function adminBoardView(tr) {	  
	var textID = $(tr).find("#textID").val();
  	$("#paramTextID").val(textID);
  	
  	$("#frm").attr("action", "/admin/adminBoardView");
  	$("#frm").submit();
  }
  
  function hitEnterKey(e){
	  if(e.keyCode == 13){
		  getSearchBoardList();
		  return false;
	  }
   }
  
  var goAdminMenuList = function(){
		location.replace("/admin/adminMenuMain");
	};
</script>
</BODY>
</HTML>
